package com.smec.moblie.activity;

import android.os.AsyncTask;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.smec.moblie.R;
import com.smec.moblie.control.MainControl;
import com.smec.moblie.crash.ExitAppUtils;

import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 近期保养遗留问题
 * Created by sunyubo on 16/2/26.
 */
public class RemesProblemHistoryActivity extends BaseActivity {
    /** 返回按钮 **/
    @BindView(R.id.imageview_back)
    ImageView imageviewBack;
    /** 历史遗留问题内容 **/
    @BindView(R.id.textView_problenHistory)
    TextView textViewProblenHistory;
    /** 工单id **/
    private String workorder_id;
    @BindView(R.id.rl_title)
    RelativeLayout rl_title;

    @Override
    protected void setContentView() {
        setContentView(R.layout.remes_act_remesproblemhistory);
    }

    @Override
    protected void initView() {
        ButterKnife.bind(this);

//        PublicControl.setMargins(rl_title, 0, getStatusBarHeight(RemesProblemHistoryActivity.this), 0, 0);

        ExitAppUtils.getInstance().addActivity(this);
    }

    @Override
    protected void getData() {
        workorder_id = getIntent().getStringExtra("workorder_id");

        new GetProblemHistory().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }

    @Override
    public void onClick(View v) {

    }

    @OnClick(R.id.imageview_back)
    public void imageview_back() {
        RemesProblemHistoryActivity.this.finish();
    }

    private class GetProblemHistory extends AsyncTask<Void,Void,Void>{

        String ret = "";
        boolean isok = true;

        @Override
        protected Void doInBackground(Void... params) {
            try {
                ret = MainControl.getProblemHistory(workorder_id);
            } catch (IOException e) {
                e.printStackTrace();
                isok = false;
            } catch (XmlPullParserException e) {
                e.printStackTrace();
                isok = false;
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void aVoid) {
            if(isok) {
                textViewProblenHistory.setText(ret);
            }else{
                Toast.makeText(RemesProblemHistoryActivity.this, "获取数据失败，请检查网络", Toast.LENGTH_SHORT).show();
                textViewProblenHistory.setText("加载数据失败");
            }
            super.onPostExecute(aVoid);
        }
    }

}
